/**
 * 
 */
package com.dsteiner.xelavos.client.model;

import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

import com.dsteiner.widgets.client.PropertyChangeCollection;
import com.dsteiner.widgets.client.domain.DataRequest;
import com.dsteiner.widgets.client.domain.Sort;
import com.dsteiner.widgets.client.rpc.SearchRequest;
import com.dsteiner.xelavos.client.domain.SearchRequestXelavos;

public class DataModel {
	
	public static final DataRequest DATAREQUEST_POLL = new DataRequest("flag-top-new");

	public static final DataRequest DATAREQUEST_SEARCH = new DataRequest("flag-search");
	
	public static final DataRequest DATAREQUEST_MY_ENTRIES = new DataRequest("flag-my-entries");

	public static final SearchRequestXelavos SEARCH_REQUEST_DEFAULT = new SearchRequestXelavos(SearchRequest.TYPE_ALL, 
			new Sort("registeredDate", false));
	
	private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(
			this);

	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		propertyChangeSupport.registerPropertyChangeListener(propertyName,
				listener);
	}
	
	private List<DataRequest> dataRequests = new ArrayList<DataRequest>();

	public List<DataRequest> getDataRequests() {
		return dataRequests;
	}

	public void setDataRequests(List<DataRequest> dataRequests) {
		List<DataRequest> oldDataRequests = this.dataRequests;
		this.dataRequests = dataRequests;
		propertyChangeSupport.firePropertyChange("dataRequests", oldDataRequests, dataRequests);
	}

	public void addDataRequest(DataRequest dataRequest) {
		List<DataRequest> dataRequests = new ArrayList<DataRequest>();
		dataRequests.addAll(this.dataRequests);
		dataRequests.add(dataRequest);
		setDataRequests(dataRequests);
	}
}